home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / bison / ActionType < prev    next >
Text File  |  1995-06-28  |  1KB  |  45 lines

  1. Action Types
  2. Previous: <Actions=>Actions> * Next: <Mid-Rule Actions=>MidRuleAct> * Up: <Semantics=>Semantics>
  3.  
  4. #Wrap on
  5. {fH4}Data Types of Values in Actions{f}
  6.  
  7. If you have chosen a single data type for semantic values, the {fCode}$${f}
  8. and {fCode}${fStrong}n{f}{f} constructs always have that data type.
  9.  
  10. If you have used {fCode}%union{f} to specify a variety of data types, then you
  11. must declare a choice among these types for each terminal or nonterminal
  12. symbol that can have a semantic value.  Then each time you use {fCode}$${f} or
  13. {fCode}${fStrong}n{f}{f}, its data type is determined by which symbol it refers to
  14. in the rule.  In this example,
  15.  
  16. #Wrap off
  17. #fCode
  18. exp:    …
  19.         | exp '+' exp
  20.             \{ $$ = $1 + $3; \}
  21. #f
  22. #Wrap on
  23.  
  24. {fCode}$1{f} and {fCode}$3{f} refer to instances of {fCode}exp{f}, so they all
  25. have the data type declared for the nonterminal symbol {fCode}exp{f}.  If
  26. {fCode}$2{f} were used, it would have the data type declared for the
  27. terminal symbol {fCode}'+'{f}, whatever that might be.
  28.  
  29. Alternatively, you can specify the data type when you refer to the value,
  30. by inserting {fEmphasis}<{fStrong}type{f}>{f} after the {fEmphasis}${f} at the beginning of the
  31. reference.  For example, if you have defined types as shown here:
  32.  
  33. #Wrap off
  34. #fCode
  35. %union \{
  36.   int itype;
  37.   double dtype;
  38. \}
  39. #f
  40. #Wrap on
  41.  
  42. then you can write {fCode}$<itype>1{f} to refer to the first subunit of the
  43. rule as an integer, or {fCode}$<dtype>1{f} to refer to it as a double.
  44.  
  45.